#include <gl/freeglut.h>

GLfloat ctrlPoints[4][4][3] =
{
    {{-3,0,4},{-2,0,2},{-1,0,0},{0,0,2}},
    {{-3,1,1},{-2,1,3},{-1,1,6},{0,1,-1}},
    {{-3,2,4},{-2,2,0},{-1,2,3},{0,2,4}},
    {{-3,3,0},{-2,3,0},{-1,3,0},{0,3,0}}
};  // 控制点

void init()
{
    glClearColor(1, 1, 1, 0);
    // 使用控制点定义Bezier曲面函数
    glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlPoints[0][0][0]);
    glEnable(GL_MAP2_VERTEX_3);
    glOrtho(-5, 5, -5, 5, -5, 5);
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(0, 0, 0);
    glPushMatrix();
    glRotatef(85, 1, 1, 1);
    for (int i = 0; i <= 20; i++)
    {
        glBegin(GL_LINE_STRIP);
        for (int j = 0; j <= 20; j++)
            glEvalCoord2f((GLfloat)i / 20, (GLfloat)j / 20);
        glEnd();
    }
    glPopMatrix();
    glFlush();
}

void main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
    glutInitWindowSize(500, 500);
    glutCreateWindow("Bezier curve surface");
    init();
    glutDisplayFunc(display);
    
    glutMainLoop();
}